package filter.pre

import com.netflix.zuul.ZuulFilter
import com.netflix.zuul.context.RequestContext
import groovy.util.logging.Slf4j

import javax.servlet.http.HttpServletRequest

/**
 * Created by twg on 2018/3/13.
 * 配合Groovy，可以实现动态加载过滤器，不需要重启服务。
 */
@Slf4j
class PreFilter extends ZuulFilter{
    @Override
    String filterType() {
        return "pre"
    }

    @Override
    int filterOrder() {
        return 1000
    }

    @Override
    boolean shouldFilter() {
        return true
    }

    @Override
    Object run() {
        HttpServletRequest request = RequestContext.currentContext.getRequest();
        log.info("This is pre filter: Send {} request to {}",request.getMethod(),request.getRequestURL().toString());
        return null
    }
}
